#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "appdatamodel.h"

int main(int argc, char *argv[])
{
    if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
        qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
        qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    }
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    // Register Model Object
    // AppDataModel *appDataModel = new AppDataModel();
    // engine.rootContext()->setContextProperty("AppDATA", appDataModel);

    qmlRegisterType<AppDataModel>("Backend", 1, 0, "AppDataModel");

    const QUrl url(QStringLiteral("qrc:/MenuMain.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
    &app, [url](QObject * obj, const QUrl & objUrl) {
        if (!obj && url == objUrl) {
            QCoreApplication::exit(-1);
        }
    }, Qt::QueuedConnection);
    engine.load(url);
    return app.exec();
}
